<?php
session_start();
ob_start();
include_once dirname(dirname(__FILE__)) . '/include/common.php';
$core = new core();
$text_search = isset($_POST["text_search"]) ? addslashes(trim($_POST["text_search"])) : 0;
$page = isset($_POST["page"]) ? intval($_POST["page"]) : 1;
$load_more=0;
$product_list = $core->searchProduct($text_search,$page,$load_more);
if ($product_list) {
    $html = '';
    foreach ($product_list as $product) {
        $html.='<tr>
                    <td>'. $product->product_name.'</td>
                    <td class="center">'. $product->product_code.'</td>
                    <td class="center">'. $product->manufacture.'</td>
                    <td class="center"><img class="photo_product" style="width: 100px;" src="photo/thumb_photo/200_'. $product->main_photo.'" rel="photo/'. $product->main_photo.'"/></td>
                    <td class="center">'. $product->description.'</td>

                    <td class="center">'. number_format($product->product_price / 1000).'</td>
                    <td class="center">';
        if ($_SESSION["user_role"] != 3) {
                $html.='<a class="btn btn-info btn_edit_category" href="addProduct.php?id='.$product->product_id.'" rel="">
                    <i class="icon-edit icon-white"></i>  
                    Edit                                            
                </a>
                <a rel="'.$product->product_id.'" class="btn btn-danger btn_delete_product" href="javascript:void(0)">
                    <i class="icon-trash icon-white"></i> 
                    Delete
                </a>';
        }
           $html.=' </td>
                </tr>';
    }
    $page = $page + 1;
    echo json_encode(array('type' => 0, 'html' => $html,'page' => $page, 'load_more' => $load_more));
    die;
} else {
    echo json_encode(array('type' => 1, 'msg' => "Không tìm thấy sản phẩm!"));
    die;
}
?>
